
import time
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

# 设置 Chrome 浏览器的路径
chrome_options = Options()
chrome_options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe"  # 修改为你自己的路径

# 使用 webdriver_manager 自动下载 ChromeDriver，并创建 Service 对象
service = Service(ChromeDriverManager().install())  # 正确实例化 Service 类

# 启动浏览器
driver = webdriver.Chrome(service=service, options=chrome_options)

driver.get("https://www.baidu.com")


#3.找到搜索框，输入关键词
driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("感动中国十大人物")
time.sleep(2)

#点击百度一下
driver.find_element(By.CSS_SELECTOR,"#su").click()
time.sleep(2)

#关闭浏览器
driver.close()